package com.terry.gametest;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.activerecord.Model;

import java.time.LocalDateTime;

/**
 * @author tanlvxu
 * @version 1.0
 * @information
 * @date 2021/11/16 9:45
 */
public class BaseEntity<T extends Model<?>> extends Model<T> {
    /**
     * 创建人
     */
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private Long createBy;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 更新人
     */
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    private Long updateBy;

    /**
     * 是否删除（0(false)：未删除；1(true)：已删除）
     */
    @TableLogic
    @TableField(value = "is_delete", fill = FieldFill.INSERT)
    private Boolean isDelete;

    @TableField(exist = false)
    private Boolean createByFill = Boolean.TRUE;

    /**
     * 是否填充修改人
     * true 采用默认填充  使用ICreateId.getId()获取ID
     * false 使用自定义updateBy默认值
     */
    @TableField(exist = false)
    private Boolean updateByFill = Boolean.TRUE;

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public Long getUpdateBy() {
        return updateBy;
    }

    /**
     * 默认填充  使用ICreateId.getId()获取ID
     * @param updateBy
     */
    public void setUpdateBy(Long updateBy) {
        this.updateBy = updateBy;
    }

    /**
     * 使用 updateBy 自身值 更新
     * @param createTime
     */
    public void setCreateNotFill(Long createBy, LocalDateTime createTime) {
        setCreateBy(createBy);
        setCreateTime(createTime);
        createByFill = Boolean.FALSE;
    }

    /**
     * 使用 updateBy 自身值 更新
     * @param updateBy
     */
    public void setUpdateByNotFill(Long updateBy, LocalDateTime updateTime) {
        setUpdateBy(updateBy);
        setUpdateTime(updateTime);
        updateByFill = Boolean.FALSE;
    }

    public Boolean getDelete() {
        return isDelete;
    }

    public void setDelete(Boolean delete) {
        isDelete = delete;
    }
}
